﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace JMY_DAL
{
     public class Dbherper
    {
        /// <summary>
        /// 连接数据库
        /// </summary>
         SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=HospitalMessage;Integrated Security=True");
        /// <summary>
        /// 返回表格数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataTable GetTable(string sql)
        {
            conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            conn.Close();
            return dt;
        }
        /// <summary>
        /// 返回首影响的行数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public int NonCaryQuery(string sql)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            int i = cmd.ExecuteNonQuery();
            conn.Close();
            return i;
        }
        /// <summary>
        /// 返回首行首列  
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public object Scalcar(string sql)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            object i = cmd.ExecuteScalar();
            conn.Close();
            return i;
        }
    }
}
